home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / doublebed.lua < prev    next >
Text File  |  2004-01-29  |  4KB  |  119 lines

  1. -- bed  state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.     
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button ;
  12.         button = addPieMenuButton("pm_sleep", "sleep");
  13.         button.addDescription(ACTIVITY, "sleep");
  14.         -- can always be selected by user
  15.         button.addDescription(ALWAYS_USERSELECTABLE, "true");
  16.         
  17.         local character = getStateObjectFromID(msg.sender);
  18.  
  19.         if (not isUser(character, this, {"lie"})) then    
  20.             local otherUsers = getOtherUsers(character, this, "lie")
  21.             if (getn(otherUsers) > 0) then
  22.                 local characterInBed = otherUsers[1];
  23.                 if activityPossible(character, "getIntimateBed", characterInBed) then
  24.                     button = addPieMenuButton("pm_getIntimateBed", "getIntimateBed");
  25.                     button.addDescription(ACTIVITY, "getIntimateBed");
  26.                 else
  27.                     -- add grayed out
  28.                     button = addPieMenuButton("pm_getIntimateBed", "getIntimateBed");
  29.                     button.addDescription(GRAYED_OUT, "true");
  30.                 end;
  31.             end
  32.         end
  33.         
  34. --        local occupants = getCharactersWithActivity("sleep");
  35. --        if (getn(occupants)>0) then
  36. --            
  37. --            button = addPieMenuButton("pm_getIntimateBed", "getIntimateBed");
  38. --            button.addDescription(ACTIVITY, "getIntimateBed");
  39. --            --button.addDescription(DONTQUEUE, "true");
  40. --        end
  41.         
  42.         
  43.     end )
  44.     
  45.     -- get intimate with a bed occupant
  46.     onMsg("getIntimateBed", function(msg)
  47.         local character = getStateObjectFromID(msg.sender);
  48.         local occupants = getOtherUsers(character, this, "lie")
  49.         
  50.         if (getn(occupants) == 0) then 
  51.             print("doublebed.lua::getIntimateBed no occupants found");
  52.             instantAbort(character, EMOTICON_CANNOT, "emoThink");
  53.             return
  54.         end
  55.         
  56.         local occupant = occupants[1];
  57.         character.sendMsg("getIntimateBed", occupant);
  58.         
  59.     end )
  60.     
  61.     -- get intimate with a bed occupant
  62.     onMsg("getIntimateBedShortcut", function(msg)
  63.         local character = getStateObjectFromID(msg.sender);
  64.         
  65.         
  66.         --local occupants = getCharactersWithActivity("sleep");
  67.         local occupants = getOtherUsers(character, this, "lie")
  68.         
  69.         if (getn(occupants) == 0) then 
  70.             print("doublebed.lua::getIntimateBed no occupants found");
  71.             --instantAbort(character, EMOTICON_CANNOT, "emoThink");
  72.             return
  73.         end
  74.         
  75.         local occupant = occupants[1];
  76.         character.sendMsg("getIntimateBedShortcut", occupant);
  77.         
  78.     end )
  79.  
  80.     -- lay on bed
  81.     onMsg("sleep", function(msg)
  82.         -- get the game object server
  83.         local gameObjectServer = getGameObjectServer();
  84.         -- get character who initiated this action
  85.         local character = getStateObjectFromID(msg.sender);
  86.         
  87.         -- check if sombody else in bed, and if we can share a bed with him
  88.         local occupants = getOtherUsers(character, this, "lie");
  89.         if (getn(occupants) > 0) then 
  90.             local occupant = occupants[1];
  91.             if (not activityPossible(character, "inBedTogether", occupant)) then
  92.                 instantAbort(character, EMOTICON_SHY, "emoRefuseChar", occupant);
  93.                 return
  94.             end
  95.         end
  96.         
  97.         -- walk to the closest action point
  98.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"layDown1", "layDown2"});
  99.         -- get the walk state object
  100.         local wso = character.walkSO;
  101.         if (actionPoint) then
  102.             -- create state machine contexts
  103.             local wsoContext = StateMachineContext();
  104.             -- store the action point
  105.             wsoContext.storeData("actionPointName", actionPoint.getName());
  106.             if (wso.walkToActionPoint(actionPoint)) then
  107.                 wso.queueStateMachine("doublebedChar.layDown", this, wsoContext);
  108.             else
  109.                 print("no path found");
  110.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  111.             end
  112.         else
  113.             print("doublebed.lua: no action point found of layDown1, layDown2");
  114.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  115.         end
  116.     end )
  117.             
  118. endStateMachine()
  119.